<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>代码生成器-参数配置</title>
    <!-- import Vue.js -->
    <script src="http://lib.baomitu.com/vue/2.6.14/vue.min.js"></script>
    <!-- import stylesheet -->
    <link rel="stylesheet" href="http://lib.baomitu.com/view-design/4.6.1/styles/iview.css">
    <!-- import iView -->
    <script  charset="utf-8" src="http://lib.baomitu.com/view-design/4.6.1/iview.js"></script>
    <script src="http://lib.baomitu.com/axios/0.21.4/axios.min.js"></script>
</head>
<body>
<div id="app" style="padding-top: 1px">
    <Tabs value="name1">
        <tab-pane label="字段配置" name="name1">
            <i-table border ref="selection" :columns="columns" :data="fields">
                <template slot-scope="{ row, index }" slot="add">
                    <Checkbox v-model="row.isAdd" @on-change="(value)=>valueChange('isAdd',value,index)"></Checkbox>
                </template>
                <template slot-scope="{ row, index }" slot="edit">
                    <Checkbox v-model="row.isEdit" @on-change="(value)=>valueChange('isEdit',value,index)"></Checkbox>
                </template>
                <template slot-scope="{ row, index }" slot="list">
                    <Checkbox v-model="row.isList" @on-change="(value)=>valueChange('isList',value,index)"></Checkbox>
                </template>
                <template slot-scope="{ row, index }" slot="statistics">
                    <Checkbox v-model="row.isStatistics"
                              @on-change="(value)=>valueChange('isStatistics',value,index)"></Checkbox>
                </template>
                <template slot-scope="{ row, index }" slot="listSlot">
                    <i-select v-model="row.listSlot" @on-change="(value)=>valueChange('listSlot',value,index)"
                              :transfer="true">
                        <i-option value="text">文本</i-option>
                        <i-option value="elipsis">长文本</i-option>
                        <i-option value="image">单张图片</i-option>
                        <i-option value="images">多张图片</i-option>
                        <i-option value="setState">设置状态</i-option>
                        <i-option value="setSortOrder">排序号</i-option>
                    </i-select>
                </template>
                <template slot-scope="{ row, index }" slot="search">
                    <Checkbox v-model="row.isSearch"
                              @on-change="(value)=>valueChange('isSearch',value,index)"></Checkbox>
                </template>
                <template slot-scope="{ row, index }" slot="required">
                    <Checkbox v-model="row.isRequired"
                              @on-change="(value)=>valueChange('isRequired',value,index)"></Checkbox>
                </template>
                <template slot-scope="{ row, index }" slot="searchType">
                    <i-select v-model="row.searchType" @on-change="(value)=>valueChange('searchType',value,index)">
                        <i-option value="eq">=</i-option>
                        <i-option value="like">like</i-option>
                    </i-select>
                </template>
                <template slot-scope="{ row, index }" slot="showType">
                    <i-select v-model="row.showType" @on-change="(value)=>valueChange('showType',value,index)">
                        <i-option value="input">文本框</i-option>
                        <i-option value="textarea">文本域</i-option>
                        <i-option value="number">数字框</i-option>
                        <i-option value="select">下拉框</i-option>
                        <i-option value="radio">单选框</i-option>
                        <i-option value="switch">开关</i-option>
                        <i-option value="date">日期</i-option>
                        <i-option value="tag">自定义标签</i-option>
                        <i-option value="percentage">百分比</i-option>
                        <i-option value="areaSelect">城市选择</i-option>
                        <i-option value="checkbox">复选框</i-option>
                        <i-option value="upload">图片上传</i-option>
                        <i-option value="file">文件上传</i-option>
                        <i-option value="video">视频上传</i-option>
                        <i-option value="point">坐标选择</i-option>
                        <i-option value="editor">富文本</i-option>
                    </i-select>
                </template>
            </i-table>
        </tab-pane>
        <tab-pane label="生成配置" name="name2">
            <i-form :model="formConfig" :label-width="120">
                <form-item label="页面布局">
                    <i-select v-model="formConfig.tempType">
                        <i-option value="1">普通列表</i-option>
                    </i-select>
                </form-item>
                <form-item label="项目路径">
                    <i-input v-model="formConfig.projectPath" autocomplete="on"></i-input>
                </form-item>
                <form-item label="父包路径">
                    <i-input v-model="formConfig.parentPackage"></i-input>
                </form-item>
                <form-item label="父模块">
                    <i-input v-model="formConfig.baseModule" autocomplete="on"></i-input>
                </form-item>
                <form-item label="子模块">
                    <i-input v-model="formConfig.moduleName" autocomplete="on"></i-input>
                </form-item>
                <form-item label="页面模块">
                    <i-input v-model="formConfig.pageModule" autocomplete="on"></i-input>
                </form-item>
                <form-item label="前端项目根路径">
                    <i-input v-model="formConfig.webDirectory" autocomplete="on"></i-input>
                </form-item>
                <form-item label="列表操作">
                    <Checkbox v-model="formConfig.addMethod">添加</Checkbox>
                    <Checkbox v-model="formConfig.editMethod">修改</Checkbox>
                    <Checkbox v-model="formConfig.delMethod">删除</Checkbox>
                    <Checkbox v-model="formConfig.batchDelMethod">批量删除</Checkbox>
                    <Checkbox v-model="formConfig.exportMethod">导出</Checkbox>
                </form-item>

                <form-item label="生成类选项">
                    <Checkbox v-model="formConfig.createController">controller</Checkbox>
                    <Checkbox v-model="formConfig.createEntity">entity</Checkbox>
                    <Checkbox v-model="formConfig.createService">service</Checkbox>
                </form-item>

                <form-item label="生成页面">
                    <Checkbox v-model="formConfig.createIndex">index</Checkbox>
                    <Checkbox v-model="formConfig.createForm">form</Checkbox>
                </form-item>

                <form-item label="生成菜单">
                    <i-switch v-model="formConfig.createMenu"/>
                </form-item>
                <form-item label="上级菜单" v-if="formConfig.createMenu">
                    <i-select v-model="formConfig.parentId" style="width:200px" filterable allow-create
                              @on-create="handleCreate" :transfer="true">
                        <i-option v-for="menu in menus" :value="menu.MENUID" :key="menu.MENUID">{{ menu.MENUNAME }}
                        </i-option>
                    </i-select>
                </form-item>
                <form-item label="菜单名称" v-if="formConfig.createMenu">
                    <i-input v-model="formConfig.menuName"></i-input>
                </form-item>

                <form-item>
                    <i-button type="primary" @click="handleSubmit('formCustom')">生成</i-button>
                </form-item>
            </i-form>
        </tab-pane>
    </Tabs>
</div>
<script>
    /*<![CDATA[*/
    new Vue({
        el: '#app',
        data: {
            tableName: '[[${tableName}]]',
            rowKey: '',
            formConfig: {
                projectPath: '[[${projectPath}]]',
                tempType: '1',
                baseModule: '[[${projectBase}]]-module',
                moduleName: '[[${projectBase}]]-bus',
                pageModule: 'business',
                baseOutPath: '',
                parentPackage: 'com.yycx.module',
                webDirectory: '[[${webPath}]]',
                addMethod: true,
                editMethod: true,
                delMethod: true,
                batchDelMethod: true,
                exportMethod: true,
                createMenu: false,
                createForm:false,
                createIndex:false,
                createEntity:true,
                createController:true,
                createService:true,
                menuName: '',
                parentMenuName:'',
                parentId: 0
            },
            columns: [
                {
                    type: 'index',
                    width: 60,
                    align: 'center'
                },
                {
                    title: '字段名',
                    width: 130,
                    key: 'name'
                },
                {
                    title: '字段描述',
                    width: 170,
                    key: 'comment'
                },
                {
                    title: "Java类型",
                    width: 120,
                    key: 'propertyType'
                },
                {
                    title: "列表",
                    slot: 'list',
                    width: 70,
                    align: 'center',
                    key: 'list'
                },
                {
                    title: "列表渲染",
                    slot: 'listSlot',
                    width: 130,
                    align: 'center',
                    key: 'listSlot'
                },
                {
                    title: "查询",
                    slot: 'search',
                    width: 70,
                    align: 'center',
                    key: 'isSearch'
                },
                {
                    title: "查询方式",
                    slot: 'searchType',
                    width: 100,
                    align: 'center',
                    key: 'searchType'
                },
                {
                    title: "添加",
                    slot: 'add',
                    width: 70,
                    align: 'center',
                    key: 'isAdd'
                },
                {
                    title: "修改",
                    slot: 'edit',
                    width: 70,
                    align: 'center',
                    key: 'isEdit'
                },
                {
                    title: "合计行",
                    slot: 'statistics',
                    width: 90,
                    align: 'center',
                    key: 'isStatistics'
                },
                {
                    title: "必填",
                    slot: 'required',
                    width: 70,
                    align: 'center',
                    key: 'isRequired'
                },
                {
                    title: "表单控件",
                    slot: 'showType',
                    width: 130,
                    align: 'center',
                    key: 'showType'
                }
            ],
            fields: [],
            menus: []
        },
        methods: {
            getTable: function () {
                let data = new FormData();
                data.append('tableName', this.tableName);
                axios.post('/generate/table', data).then((response) => {
                    this.fields = response.data.data.fields;
                    this.rowKey = response.data.data.rowKey;
                    this.formConfig.menuName = response.data.data.menuName;
                }).catch((error) => {
                    console.log(error);
                });
            },
            getMenus: function () {
                axios.post('/generate/menus', {}).then((response) => {
                    this.menus = response.data.data;
                }).catch((error) => {
                    console.log(error);
                });
            },
            valueChange: function (field, value, index) {
                this.fields[index][field] = value
            },
            handleCreate(val) {
                this.menus.push({
                    MENUID: val,
                    MENUNAME: val
                });
                this.formConfig.parentMenuName = val;
            },
            handleSubmit: function () {
                let data = new FormData();
                data.append('fields', JSON.stringify(this.fields));
                data.append('tableName', this.tableName);
                data.append('rowKey', this.rowKey);
                data.append('projectPath', this.formConfig.projectPath);
                data.append('baseModule', this.formConfig.baseModule);
                data.append('moduleName', this.formConfig.moduleName);
                data.append('parentPackage', this.formConfig.parentPackage);
                data.append('pageModule', this.formConfig.pageModule);
                data.append('webDirectory', this.formConfig.webDirectory);
                data.append('addMethod', this.formConfig.addMethod);
                data.append('editMethod', this.formConfig.editMethod);
                data.append('delMethod', this.formConfig.delMethod);
                data.append('batchDelMethod', this.formConfig.batchDelMethod);
                data.append('exportMethod', this.formConfig.exportMethod);
                data.append('createMenu', this.formConfig.createMenu);
                data.append('menuName', this.formConfig.menuName);
                data.append('parentId', this.formConfig.parentId);
                data.append('parentMenuName', this.formConfig.parentMenuName);

                data.append('createForm', this.formConfig.createForm);
                data.append('createIndex', this.formConfig.createIndex);
                data.append('createEntity', this.formConfig.createEntity);
                data.append('createController', this.formConfig.createController);
                data.append('createService', this.formConfig.createService);
                axios.post('/generate/build', data).then((response) => {
                    this.$Message.success("生成成功");
                    console.log(response.data.data)
                }).catch((error) => {
                    console.log(error);
                });
            }
        },
        created: function () {
            this.getTable()
            this.getMenus()
        }
    })
    /*]]>*/
</script>
</body>
</html>
